package com.剑指offer;

/*
* 输入一棵二叉树，判断该二叉树是否是平衡二叉树。
* */
public class _39判断平衡二叉树
{
    public boolean IsBalanced_Solution(TreeNode root)
    {
        if (root == null)
        {
            return true;
        }
        if (Math.abs(getHight(root.left) - getHight(root.right)) > 1)
        {
            return false;
        }

        return IsBalanced_Solution(root.left) && IsBalanced_Solution(root.right);

    }

    public int getHight(TreeNode root)
    {
        if (root == null)
        {
            return 0;
        }
        return max(getHight(root.left), getHight(root.right)) + 1;
    }

    public int max(int a, int b)
    {
        return a > b ? a : b;
    }


}
